package com.feeyo.groundservice.composewidget.usage

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.draggable2D
import androidx.compose.foundation.gestures.rememberDraggable2DState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.ThumbUp
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.feeyo.groundservice.composewidget.usage.base.BaseComposeActivity
import com.feeyo.groundservice.base_util.toast
import com.feeyo.groundservice.composewidget.util.dpToPx
import com.feeyo.groundservice.composewidget.view.menu_fab.FloatDraggableButton
import com.feeyo.groundservice.composewidget.view.menu_fab.MenuFabItem
import com.feeyo.groundservice.composewidget.view.menu_fab.MenuFloatingActionButton
import okhttp3.internal.wait
import kotlin.math.roundToInt

/**
 *作者：QLH on 2023-08-10
 *描述：
 */
class MenuFabActivity : BaseComposeActivity() {

    private val menuItems = ArrayList<MenuFabItem>().apply {
        add(
            MenuFabItem(
                icon = {
                    Icon(
                        modifier = Modifier.size(16.dp),
                        imageVector = Icons.Default.Delete,
                        contentDescription = "",
                        tint = Color.White
                    )
                },
                "删除"
            )
        )
        add(
            MenuFabItem(
                icon = {
                    Icon(
                        modifier = Modifier.size(16.dp),
                        imageVector = Icons.Default.ThumbUp,
                        contentDescription = "",
                        tint = Color.White
                    )
                },
                "更新"
            )
        )
    }


    @OptIn(ExperimentalFoundationApi::class)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val size = remember { mutableStateOf(IntSize(0, 0)) }
            Box(
                modifier = Modifier.fillMaxSize()
                    .onSizeChanged {
                        size.value = it
                    }) {
                MenuFloatingActionButton(
                    Icons.Default.Add,
                    items = menuItems,
                    modifier = Modifier.align(Alignment.BottomEnd).padding(bottom = 30.dp),
                ) {
                    toast(it.label)
                }


                FloatDraggableButton(
                    parentWidth = size.value.width,
                    parentHeight = size.value.height,
                    btnWidth = 60.dp.dpToPx(),
                    btnHeight = 60.dp.dpToPx(),
                    bgColor = Color.Red,
                    shape = RoundedCornerShape(30.dp),
                    onClick = {},
                    content = {}
                )
            }
        }
    }


    @Preview
    @Composable
    fun Image() {
        Icon(
            imageVector = Icons.Default.Delete,
            contentDescription = "",
            tint = Color.Red
        )
    }
}